# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=gdb
pkgver=7.9
pkgrel=1
_gcc_ver=4.9.2
pkgdesc="GNU Debugger (MSYS2 version)"
arch=('i686' 'x86_64')
license=('GPL3')
url="http://www.gnu.org/software/gdb/"
groups=('base-devel')
depends=("libiconv" "zlib" "expat" "libiconv" "python2" "libexpat" "libreadline")
#checkdepends=('dejagnu' 'bc')
makedepends=("libiconv-devel" "zlib-devel" "ncurses-devel" "liblzma-devel" "libexpat-devel" "libreadline-devel")
options=('staticlibs' '!distcc' '!ccache')
source=("http://ftp.gnu.org/gnu/gdb/gdb-${pkgver}.tar.xz"{,.sig}
        'gdbinit'
        'gdb-7.8.1-msysize.patch'
        '7.8-symtab-cygwin.patch'
        '7.8-windows-nat-cygwin.patch')
md5sums=('e6279f26559d839f0b4218a482bcb43e'
         'SKIP'
         'dec2439447cb1accf037457b459093f7'
         'd97a2b6c4f1ffc6f7cc56e4f89f3fcfb'
         'cb8147558034aa16f3defcb4cc1d7bf7'
         '7f519f89aa661fde76446735798aff4d')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}

  patch -p2 -i ${srcdir}/7.8-symtab-cygwin.patch
  patch -p2 -i ${srcdir}/7.8-windows-nat-cygwin.patch
  patch -p1 -i ${srcdir}/gdb-7.8.1-msysize.patch

  # hack! - libiberty configure tests for header files using "$CPP $CPPFLAGS"
  sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" libiberty/configure
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure \
    --build=${CHOST} \
    --host=${CHOST} \
    --prefix=/usr \
    --enable-64-bit-bfd \
    --disable-werror \
    --with-system-gdbinit=/etc/gdbinit \
    --with-python=/usr/bin/python2 \
    --without-tcl \
    --without-tk \
    --without-guile \
    --with-expat \
    --with-lzma \
    --with-system-readline \
    --with-libiconv-prefix=/usr \
    --with-zlib \
    --enable-tui
  make
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install

  # install "custom" system gdbinit
  install -D -m644 ${srcdir}/gdbinit ${pkgdir}/etc/gdbinit
  sed -i 's|%GCC_NAME%|gcc-'${_gcc_ver}'|g' ${pkgdir}/etc/gdbinit

  # these are shipped by binutils
  rm -fr ${pkgdir}/usr/{include,lib}/ ${pkgdir}/usr/share/locale/
  rm -f ${pkgdir}/usr/share/info/{bfd,configure,standards}.info
}
